/*
 * @Author: FanWeiHua
 * @Date: 2021-07-08 10:53:04
 * @LastEditTime: 2021-07-08 11:07:16
 * @Description: 路由映射（路由鉴权）
 */
'use strict';
import React from 'react';
import { Route, Redirect, Switch } from 'react-router-dom';
const renderRoutes = (routes, authPath = '/', extraProps = {}, switchProps = {}) => {
  return routes ? (
    <Switch {...switchProps}>
      {routes.map((route, i) => (
        <Route
          key={route.key || i}
          path={route.path}
          exact={route.exact}
          strict={route.strict}
          render={props => {
            return <route.component {...props} {...extraProps} route={route} routes={routes} />;
            // 可以需要的路由鉴权设置
            // return <Redirect to={{ pathname: authPath, state: { from: props.location } }} />;
          }}
        />
      ))}
    </Switch>
  ) : null;
};
export default renderRoutes;
